package com.eedi.framework.logger.service;

import com.eedi.framework.common.pojo.PageResult;
import com.eedi.framework.common.util.object.BeanUtils;
import com.eedi.framework.logger.controller.sys.vo.loginlog.SysLoginLogPageReq;
import com.eedi.framework.logger.controller.sys.vo.loginlog.SysLoginLogCreateReq;
import com.eedi.framework.logger.controller.sys.vo.loginlog.SysLogoutLogCreateReq;
import com.eedi.framework.logger.dal.dataobject.SysLogLoginDO;
import com.eedi.framework.logger.dal.mapper.SysLoginLogMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;

/**
 * 登录日志 Service 实现
 */
@Service
@Validated
public class SysLoginLogServiceImpl implements SysLoginLogService {

    private static final Logger log = LoggerFactory.getLogger(SysLoginLogServiceImpl.class);
    @Resource
    private SysLoginLogMapper sysLoginLogMapper;

    @Override
    public PageResult<SysLogLoginDO> getLoginLogPage(SysLoginLogPageReq pageReqVO) {
        return sysLoginLogMapper.selectPage(pageReqVO);
    }

    @Override
    public void createLoginLog(SysLoginLogCreateReq reqDTO) {
        SysLogLoginDO loginLog = BeanUtils.toBean(reqDTO, SysLogLoginDO.class);
        loginLog.setLoginResult(reqDTO.getResult());
        loginLog.setLoginId(reqDTO.getSysUserLoginId());
        sysLoginLogMapper.insert(loginLog);
    }

    @Override
    public void createLogoutLog(SysLogoutLogCreateReq reqDTO) {
        SysLogLoginDO loginLog = BeanUtils.toBean(reqDTO, SysLogLoginDO.class);
        loginLog.setLoginResult(reqDTO.getResult());
        sysLoginLogMapper.insert(loginLog);
    }

}
